<template>
    <nly-row class="DynamicForm form-inline" v-show="isOk">
        <!-- <nly-col xs="12" :sm="(item.type == '区块' || item.type == '快速文本') ? '12' : '12'" :lg="(item.type == '区块' || item.type == '快速文本')? '12' : '12'" v-for="(item) in initFormData" :key="item.id"> -->
        <nly-col xs="12" sm="'12'" :lg="showListStatus?'12':'6'" v-for="(item) in initFormData" :key="item.id">
            <input-group-search v-if="item.type == '搜索选择' && showSearch" :title="item.name" :modalTitle="'选择'+item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]" :valueTitle.sync="formPostData[IdFieldToNameField(item.code)]" :treeType="item.val" :clearValueIcon="false"></input-group-search>
            <form-input v-if="item.type == '文本'" :disabled="item.code == 'visitSign'? true : false" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]" :blurEvent="blurEventMap.get(item.code)"></form-input>
            <form-text-area v-if="item.type == '区块'" :title="item.name" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]"></form-text-area>
            <form-fast-area v-if="item.type == '快速文本'" :title="item.name" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]"></form-fast-area>
            <form-select v-if=" item.type == '下拉'  || item.type == '性别'" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :required="item.onFill" v-model="formPostData[item.code]" :dataList="valForFormFN(item.val)">
            </form-select>
            <form-radio v-if="item.type == '单选'" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]" :keyPre="getOnlyCode(item)" :dataList="valForFormFN(item.val)">
            </form-radio>
            <form-check-box v-if="item.type == '复选'" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]" :dataList="valForCheckBoxFN(item.val)">
            </form-check-box>
            <a-checkbox v-if="item.type == '复选框'" v-model="formPostData[item.code]">
                {{item.name}}
            </a-checkbox>
            <form-radio v-if="item.type == '是否'" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]" :keyPre="getOnlyCode(item)" :dataList="[
                    { key: item.dataType == 1 ? true : '是', title: '是' },
                    { key: item.dataType == 1 ? false : '否', title: '否' }
                ]"></form-radio>
            <form-date-picker v-if="item.type == '日期'" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]"></form-date-picker>
            <form-date-picker v-if="item.type == '时间'" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]" show-time format="YYYY-MM-DD HH:mm"></form-date-picker>
            <form-input-number v-if="item.type == '整数'" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]" :min="item.val ? 0 : -Infinity" :precision="0"></form-input-number>
            <form-input-number v-if="item.type == '小数'" :title="item.name" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.'+item.code]" :name="item.code" :required="item.onFill" v-model="formPostData[item.code]" :precision="0.1"></form-input-number>
        </nly-col>
    </nly-row>
</template>

<script>

import { valForFormFN, valForCheckBoxFN, getOnlyCode, IdFieldToNameField } from "@/utils/customize"



export default {
    name: "DynamicForm",
    props: {
        formPostData: {
            type: Object,
            default: () => ({})
        },
        initFormData: {
            type: Array,
            default: () => []
        },
        errors: {
            type: Object,
            default: () => ({})
        },
        isOk: {
            type: Boolean,
            default: true
        },
        blurEventMap: {
            type: Map,
            default: () => new Map()
        },
        showSearch: {
            type: Boolean,
            default: true
        },
        showListStatus: {
            type: Boolean,//from显示状态(true:一排一个 还是 false:一排两个)
            default: true
        }

    },
    data () {
        return {
            valForFormFN,
            valForCheckBoxFN,
            getOnlyCode,
            IdFieldToNameField
        }
    },
    beforeCreate () {


    },
    created () {

    },
    mounted () {
        console.log("DynamicForm_formData", this.initFormData, this.blurEventMap);
    },
    computed: {
        //  msgErrors:function(){
        //      console.log("DynamicForm_errors",this.errors)
        //     return this.errors;
        // }
    },
    methods: {
        reload () {
            this.$forceUpdate()
        }
    },
    watch: {

    }
}
</script>

<style lang="less">
    .DynamicForm {
        .ant-radio-wrapper {
            font-size: 1rem !important;
            padding: 0 !important;
            span.ant-radio + * {
                padding-right: 4px !important;
                padding-left: 0px !important;
            }
        }
        .myRightClass {
            flex: 1;
            white-space: nowrap;
            text-overflow: ellipsis;
            width: auto !important;
            overflow: hidden;
            input,
            .ant-select {
                overflow: hidden;
            }
        }
        .ant-select-selection__rendered,
        .ant-select-selection-selected-value,
        .ant-select-selection {
            height: 28px;
            line-height: 28px;
        }
    }
</style>